package ZiFuStream.FileReader;

import com.sun.jdi.Value;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.function.Function;
import java.util.function.IntFunction;

public class Demo3 {
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("day24\\a.txt");

        StringBuilder sb = new StringBuilder();
        int ch;
        while ((ch = fr.read()) != -1) {
            sb.append((char) ch);
        }
        fr.close();

//        Integer[] arr = Arrays.stream(sb.toString()
//                        .split("-"))
//                .map(new Function<String, Integer>() {
//                    @Override
//                    public Integer apply(String s) {
//                        return Integer.parseInt(s);
//                    }
//                })
//                .sorted()
//                .toArray(new IntFunction<Integer[]>() {
//                    @Override
//                    public Integer[] apply(int value) {
//                        return new Integer[value];
//                    }
//                });

        Integer[] arr = Arrays.stream(sb.toString()
                        .split("-"))
                .map(Integer::parseInt)
                .sorted()
                .toArray(Integer[]::new);

        FileWriter fw=new FileWriter("day24\\a.txt");

        String s = Arrays.toString(arr).replace(", ", "-");
        String result = s.substring(1, s.length() - 1);
        System.out.println(result);

        fw.write(result);
        fw.close();
    }
}
